# -*- coding: utf-8 -*-
# @author okumura@laurus.co.jp

from google.appengine.ext import webapp
from django.template.defaultfilters import stringfilter
from django.utils.html import escape
from model.pigeon import Pigeon
import datetime

register = webapp.template.create_template_register()

@register.filter
@stringfilter
def truncate(value, length):
    if len(value) > length - 1:
        return value[:length - 1] + u'…'
    else:
        return value

@register.filter
def tz(value):
    if not isinstance(value, datetime.datetime):
        return value

    diff = 9
    # @todo できればここでクライアントのタイムゾーンを取得して自動的にdiffを書き換えたい
    return value + datetime.timedelta(hours=diff)

@register.filter
@stringfilter
def importance(value):
    importances = dict(Pigeon.importances)
    try:
        return importances[value]
    except:
        return ''
